package com.cetccst.securitysuite.network;

import android.content.Context;

import cn.com.cetccst.network.IRetrofitClient;
import cn.com.cetccst.network.RetrofitManager;
import cn.com.cetccst.network.log.IHttpLog;
import com.cetccst.securitysuite.network.respone.UserResponse;

import retrofit2.Call;
import retrofit2.Retrofit;

public class UserHttpRequester {

    private static IRetrofitClient retrofitClient;
    private static IHttpLog httpLogConfig;
    private static IUserApiService apiService;
    private static UserHttpRequester httpRequester;
    private UserHttpRequester(){}
    public static void initialize(Context context) {
        if (retrofitClient == null) {
            retrofitClient = new RetrofitManager.Builder(context, "http://10.100.241.152:8080/").setLogLevel(IHttpLog.Level.BODY).build();
            Retrofit retrofit = retrofitClient.getRetrofit();
            httpLogConfig = retrofitClient.getHttpLogConfig();
            apiService = retrofit.create(IUserApiService.class);
        }
    }

    public static IHttpLog getHttpLogConfig() {
        return httpLogConfig;
    }

    public static UserHttpRequester getInstance() {
        if (httpRequester == null) {
            httpRequester = new UserHttpRequester();
        }
        return httpRequester;
    }

    public void getJsonUser(HttpCallback<UserResponse> callback) {
        Call<UserResponse> call = apiService.getUserJsonResponse();
        call.enqueue(callback);
    }
    public void getXmlUser(HttpCallback<UserResponse> callback) {
        Call<UserResponse> call = apiService.getUserXmlResponse();
        call.enqueue(callback);
    }
}
